// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLShowPartitionsStmt.h"
#include "SQLExprTableSource.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "SQLAssignItem.h"

SQLShowPartitionsStmt::SQLShowPartitionsStmt()
    : SQLStatementImpl(DbType_ptr(new DbType(&DbType::odps)))
{
  partition = std::make_shared<std::list<SQLAssignItem_ptr>>();
}

SQLExprTableSource_ptr SQLShowPartitionsStmt::getTableSource()
{
  return tableSource;
}

void SQLShowPartitionsStmt::setTableSource(SQLExpr_ptr table)
{
  if (table == nullptr)
  {
    return;
  }

  setTableSource(SQLExprTableSource_ptr(new SQLExprTableSource(table)));
}

void SQLShowPartitionsStmt::setTableSource(SQLExprTableSource_ptr tableSource)
{
  this->tableSource = tableSource;
}

SQLAssignItem_list_ptr SQLShowPartitionsStmt::getPartition()
{
  return partition;
}

SQLExpr_ptr SQLShowPartitionsStmt::getWhere()
{
  return where;
}

void SQLShowPartitionsStmt::setWhere(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLShowPartitionsStmt));
  }
  this->where = x;
}

// @Override
void SQLShowPartitionsStmt::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLShowPartitionsStmt)))
  {
    acceptChild(visitor, tableSource);
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLAssignItem, SQLObject>(partition);
    acceptChild(visitor, tmp);
    acceptChild(visitor, where);
  }
  visitor->endVisit(SharedObject(SQLShowPartitionsStmt));
}
